/*
 * Modified by edhong to remove unwanted options. 
 * Jan 2008
 *
 * QccPack: Quantization, compression, and coding utilities
 * Copyright (C) 1997-2007  James E. Fowler
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */


#include "imgidwt.h"

#define USG_STRING "[-w %s:wavelet] [-b %s:boundary]  %s:subband_pyramid %s:imgfile"

QccWAVWavelet Wavelet;
QccString WaveletFilename = QCCWAVWAVELET_DEFAULT_WAVELET;
QccString Boundary = "symmetric";

QccWAVSubbandPyramid MaskSubbandPyramid;

QccWAVSubbandPyramid SubbandPyramid;
QccIMGImage OutputImage;

int NumCols;
int NumRows;
int NumSubbands;

int main(int argc, char *argv[])
{
  int subband;

  QccInit(argc, argv);

  QccWAVWaveletInitialize(&Wavelet);
  QccWAVSubbandPyramidInitialize(&SubbandPyramid);
  QccIMGImageInitialize(&OutputImage);
  
  if (QccParseParameters(argc, argv,
                         USG_STRING,
                         WaveletFilename,
                         Boundary,
                          SubbandPyramid.filename,
                         OutputImage.filename))
    QccErrorExit();
      
  if (QccWAVWaveletCreate(&Wavelet, WaveletFilename, Boundary))
    {
      QccErrorAddMessage("%s: Error calling QccWAVWaveletCreate()",
                         argv[0]);
      QccErrorExit();
    }
  
  if (QccWAVSubbandPyramidRead(&SubbandPyramid))
    {
      QccErrorAddMessage("%s: Error calling QccWAVSubbandPyramidRead()",
                         argv[0]);
      QccErrorExit();
    }

  NumSubbands = 
    QccWAVSubbandPyramidNumLevelsToNumSubbands(SubbandPyramid.num_levels);
  NumRows = SubbandPyramid.num_rows;
  NumCols = SubbandPyramid.num_cols;


      if (QccWAVSubbandPyramidInverseDWT(&SubbandPyramid,
                                         &Wavelet))
        {
          QccErrorAddMessage("%s: Error calling QccWAVSubbandPyramidInverseDWT()",
                         argv[0]);
          QccErrorExit();
        }

  OutputImage.Y.num_rows = NumRows;
  OutputImage.Y.num_cols = NumCols;
  OutputImage.Y.image = SubbandPyramid.matrix;

  if (QccIMGImageSetMaxMin(&OutputImage))
    {
      QccErrorAddMessage("%s: Error calling QccIMGImageSetMaxMin()",
                         argv[0]);
      QccErrorExit();
    }

  if (QccIMGImageWrite(&OutputImage))
    {
      QccErrorAddMessage("%s: Error calling QccIMGImageWrite()",
                         argv[0]);
      QccErrorExit();
    }

  QccWAVWaveletFree(&Wavelet);
  QccIMGImageFree(&OutputImage);

  QccExit;
}
